#include "stdafx.h"

#include "VideoFrameView.h"


// swscale
// https://github.com/jeeb/matroska_thumbnails/blob/master/cli_test/cli_test.cpp



// DC
// http://www.codeproject.com/Articles/1988/Guide-to-WIN-Paint-for-Beginners


void DrawFrame(unsigned char* pdata);


void DrawerInit(Drawer* pDrawer)
{
	BITMAPINFO bmi = {0};
	bmi.bmiHeader.biBitCount = 24;
	bmi.bmiHeader.biCompression = BI_RGB;
	bmi.bmiHeader.biHeight = -(pDrawer->height);
	bmi.bmiHeader.biWidth = pDrawer->width;
	bmi.bmiHeader.biPlanes = 1;
	bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
	bmi.bmiHeader.biSizeImage = pDrawer->width * pDrawer->height * 3;

	pDrawer->hbmp = CreateDIBSection(pDrawer->hdcscr, &bmi, DIB_RGB_COLORS, &(pDrawer->pbmpdata) , NULL, 0); //&pbmpdata

	*pDrawer->pbmplinesize = bmi.bmiHeader.biWidth * 3;
}


void DrawerDeinit(void)
{
}


void DrawerDrawFrame(void* pParam)
{
	VideoFrameView* pVFV = (VideoFrameView *)pParam;

	HDC hdcmem = CreateCompatibleDC(pVFV->m_drawer.hdcscr);

	HGDIOBJ old = SelectObject(hdcmem,pVFV->m_drawer.hbmp);

#if 0
	BitBlt(pVFV->m_drawer.hdcscr, 0, 0, pVFV->m_drawer.width, pVFV->m_drawer.height, hdcmem, 0, 0, SRCCOPY);
#else 
	// reduce picture size
	SetStretchBltMode(pVFV->m_drawer.hdcscr, COLORONCOLOR);
	StretchBlt(pVFV->m_drawer.hdcscr, 0, 0, 720, 430, hdcmem, 0, 0, 1280, 720, SRCCOPY);
#endif

	SelectObject(hdcmem,old);

	DeleteDC(hdcmem);
}
